package com.xz.log.integration.sample.rest;

import com.xz.log.common.logging.sample.CommonLoggingSample;
import com.xz.log.integration.sample.beans.UserBean;
import com.xz.log.jul.sample.JulSample;
import com.xz.log.log4j.sample.Log4jSample;
import com.xz.log.log4j2.sample.Log4j2Sample;
import com.xz.log.logback.sample.LogbackSample;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.WebApplicationContext;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * Created by fingal on 2018/7/18.
 */
@Slf4j
@RestController
@Scope(WebApplicationContext.SCOPE_REQUEST)
@RequestMapping(value = "/user",produces = {"application/json;charset=UTF-8"})
public class UserRest {
    private static final List<UserBean> users = new ArrayList<UserBean>() {
        {
            add(new UserBean("fingal", 18, true, "广东深圳"));
            add(new UserBean("xz", 18, true, "广东深圳"));
            add(new UserBean("jin", 18, true, "广东中山"));
            add(new UserBean("fang", 18, true, "广东汕头"));
            add(new UserBean("fangjin", 18, true, "广东揭阳"));
        }
    };
    @RequestMapping(value="/{name}", method = RequestMethod.GET)
    public @ResponseBody UserBean getByName(@PathVariable String name) {
        UserBean result = users.stream()
                                .filter(user -> name.equals(user.getName()))
                                .findFirst()
                                .get();
        log.info("user : [{}]", result.toString());
        return result;
    }

    @RequestMapping(value="/log", method = RequestMethod.GET)
    public void log() {
        JulSample.getInstance().log();
        CommonLoggingSample.getInstance().log();
        Log4j2Sample.getInstance().log();
        Log4jSample.getInstance().log();
        LogbackSample.getInstance().log();
    }
}
